<?php
namespace app\common\library\helper;

class DateHelper{

    private static $_time = null;

    public static function timestampCurrent(){

        if( ! self::$_time ){

            self::$_time = time();

        }

        return self::$_time;

    }

    public static function timestampDay($timestamp = null ){

        if( ! $timestamp ){
            $timestamp = self::timestampCurrent();
        }

        return strtotime( date( 'Y-m-d', $timestamp ) );

    }

    public static function timestampAddYear( $timestamp ){

        $res = $timestamp + 86400 * 366 - 1;

        return $res;

    }

    public static function strtotime( $datetime ){

        $datetime = new \DateTime( $datetime );

        return $datetime->getTimestamp();

    }

    public static function year(){

        return date( 'Y' );

    }

    //生成执行时间戳过去的月份数组
    public static function generateMonthArr( $timestamp, $number ){

        $timestamp_month = strtotime( date( 'Y-m', $timestamp ) );

        $month_arr = [];

        for( $i = 0; $i < $number; $i++ ){

            $month_arr[] = date( 'Y-m', strtotime( "-{$i} month", $timestamp_month ) );

        }

        return $month_arr;

    }

}